package com.zis.auction.controller;

import com.zis.auction.model.Counsel;
import com.zis.auction.service.ICounselInter;
import com.zis.core.SearchParams;
import org.beetl.sql.core.engine.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * Create by wangshen 2018/1/12
 */
@RestController
@RequestMapping("/api/auction/counsel")
public class CounselController {

    @Autowired
    private ICounselInter counselInter;


    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public PageQuery<Counsel> findByPage(@RequestBody SearchParams params) throws Exception {
        return counselInter.findByPage(params);
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public String update(HttpServletRequest request, @RequestBody Counsel counsel) throws Exception {
        counsel.setUpdateUser(request.getAttribute("code").toString());
        return counselInter.update(counsel);
    }

    @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
    @ResponseBody
    public String delete(@PathVariable("id") String id) throws Exception{
        return counselInter.delete(id);
    }

    @RequestMapping(value = "/select/{id}", method = RequestMethod.GET)
    @ResponseBody
    public Counsel select(@PathVariable("id") String id) throws Exception{
        return counselInter.selectById(id);
    }
}
